package net.huashitong.Indicators.web;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.huashitong.Indicators.databean.CompletionClassificationDatabean;
import net.huashitong.Indicators.databean.IndicatorBreakdownDatabean;
import net.huashitong.Indicators.entity.TertiaryIndustry;
import net.huashitong.Indicators.filter.IndicatorBreakdownFilter;
import net.huashitong.Indicators.service.AgricultureService;
import net.huashitong.Indicators.service.TertiaryIndustryService;
import net.huashitong.Indicators.utils.CodeUtils;
import net.huashitong.Indicators.utils.DateForIndUtils;
import net.huashitong.Indicators.utils.ThiTitleUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;

/**
 * 农林牧渔业
 * @author lzr
 *
 */
@Controller
@RequestMapping("/app/agriculture")
public class AgricultureAppController extends JsonBaseController {

	@Autowired
	private AgricultureService agricultureService;
	@Autowired
	private TertiaryIndustryService industryService;
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * 农林牧渔业二级所有数据
	 * @param filter
	 * @return
	 * @throws ParseException 
	 */
	@ResponseBody
	@RequestMapping("/queryNLMYYSecView")
	public Message queryNLMYYSecView(@RequestBody IndicatorBreakdownFilter filter) throws ParseException{
		String date = filter.getDate();
		String cuDate = filter.getCurrentMonth();
		List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		
		//农林牧渔业全市各县区排名情况
		List<IndicatorBreakdownDatabean> databeans = agricultureService.queryCountyRank(filter);
		map.put("type", "1");
		map.put("data", databeans);
		map.put("unit", "亿元");
		map.put("title", "该指标全市排名一览");
		map.put("descOne", date.substring(0, 4)+ThiTitleUtils.GXQZZL);
		map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GXQJDZ);
		map.put("secTitle", "农林牧渔业总产值全市各县区排名情况");
		maps.add(map);
		
		// 农林牧渔业当季同比增长情况
		databeans = agricultureService.queryDevelopmentSituation(filter);
		map = new HashMap<String, Object>();
		map.put("type", "2");
		map.put("data", databeans);
		map.put("monthOrQuarter", CodeUtils.monthOrQuarter_qua);
		map.put("descOne", ThiTitleUtils.DJTBZZL);
		map.put("descTwo", ThiTitleUtils.DJLJZZL);
		map.put("title", "该指标发展情况");
		map.put("secTitle", "农林牧渔业总产值当季同比增长情况");
		maps.add(map);
		
		//农林牧渔业各季度绝对值及同比增长情况
		List<Map<String, Object>> list = agricultureService.queryAbsoluteValue(filter);
		/*map = new HashMap<String, Object>();
		map.put("type", "3");
		map.put("data", list);
		map.put("unit", "亿元");
		map.put("descOne", date.substring(0, 4)+ThiTitleUtils.GJTBZZL);
		map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GJJDZ);
		map.put("descThi", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GJJDZ);
		map.put("monthOrQuarter", CodeUtils.monthOrQuarter_qua);
		map.put("title", "该指标各季度同比增长情况");
		map.put("secTitle", "农林牧渔业总产值各季度绝对值及同比增长情况");
		maps.add(map);*/
		
		//农林牧渔业累计同比增长情况
		filter.setDate(date);
		list = agricultureService.queryCumulativeGrowth(filter);
		map = new HashMap<String, Object>();
		map.put("type", "4");
		map.put("data", list);
		map.put("monthOrQuarter", CodeUtils.monthOrQuarter_qua);
		map.put("unit", "亿元");
		map.put("descOne", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GJTBZZL);
		map.put("descTwo", date.substring(0, 4)+ThiTitleUtils.GJTBZZL);
		map.put("descThi", DateForIndUtils.getNextYearDate(date.substring(0, 4),-1)+ThiTitleUtils.GJLJJDZ);
		map.put("descFou", date.substring(0, 4)+ThiTitleUtils.GJLJJDZ);
		map.put("title", "该指标累计同比增长情况");
		map.put("secTitle", "农林牧渔业总产值累计绝对值及同比增长情况");
		maps.add(map);
		
		//农林牧渔业该指标各行业分类占比情况
		List<CompletionClassificationDatabean> classifications = agricultureService.queryByHYValue(filter);
		map = new HashMap<String, Object>();
		map.put("type", "9");
		map.put("data", classifications);
		map.put("unit", "万元");
		map.put("title", "该指标各行业分类占比情况");
		map.put("secTitle", "农林牧渔业总产值按行业分类情况2016年(第四季度)");
		maps.add(map);
		map = new HashMap<String, Object>();
		filter.setCurrentMonth(cuDate);
	    TertiaryIndustry industry = industryService.queryByfilter(filter);
	    map.put("leadership", industry.getLeadership());
		map.put("unitsNumber", industry.getUnitsNumber());
		map.put("lists", maps);
		map.put("title", "农林牧渔业总产值运行情况");
		return coverMessage("200", "获取成功",map);
	}
}
